package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.oldplayerreturn.OldPlayerReturnUserData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.oldplayerreturn.OldPlayerReturnMgr;
import com.yanqu.road.utils.property.PropertyHelper;

public class ReturnRoleRmbMallRecharge extends BaseRecharge {
    public ReturnRoleRmbMallRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        OldPlayerReturnUserData userData = OldPlayerReturnMgr.getUserData(player.getUserId());
        if (userData == null) {
            return true; //不是回归玩家不给买
        }
        int ret = player.getModule(OldPlayerReturnModule.class).checkReturnRoleIsEffective(userData);
        if (ret != 0) {
            return true; //不是回归玩家不给买
        }
        if (userData.getRmbMallLimit() == null){
            return false;
        }

        if (userData.getRmbMallLimit().containsKey(mallInfo.getMallId())) {
            if (userData.getRmbMallLimit().get(mallInfo.getMallId()) >= mallInfo.getLimitBuyCount()) {
                return true;
            }
        }


        return false;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        if(null == mallInfo){
            logger.error("ReturnRoleRmbMall add mall fail,mallInfo is null,orderNo:{}", orderNo);
            return "";
        }
        OldPlayerReturnMgr.addRmbMallBuyTime(player.getUserId(),mallInfo.getMallId(),1);
        player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(mallInfo.getReward()),
                eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        return mallInfo.getReward();
    }
}
